﻿using System.Windows.Forms;
using LinkDownloader.Core;
using LinkDownloader.DownloadManger;

namespace LinkDownloader.Forms.JobLists
{
    internal class JobListRow : DataGridViewRow
    {
        
        private SingleDownload download = null;
        public SingleDownload DownloadJob
        {
            get { return this.download; }
        }

        private JobList list = null;
        public JobList List
        {
            get { return this.list; }
        }

        public JobListRow(JobList list, SingleDownload download)
            : base()
        {

            this.list = list;
            this.download = download;

            this.InitializeComponent();

        }

        private void InitializeComponent()
        {

            this.CreateCells(this.list);

            this.Cells[this.list.GetColumn(JobList.ColumnNameProgress)] = new JobListCellProgress(this.list, this.download);
            
            this.UpdateAllValues();
            
        }

        public void UpdateAllValues()
        {

            this.Cells[this.list.GetColumn(JobList.ColumnNameLink)].Value = this.download.Link;
            this.Cells[this.list.GetColumn(JobList.ColumnNameSize)].Value = "-";
            this.UpdateStatus();
            this.UpdateProgress();
            this.Cells[this.list.GetColumn(JobList.ColumnNameTimeLeft)].Value = "-";
            this.UpdateTransferRate();
            
        }

        public void UpdateSize()
        {
            this.Cells[this.list.GetColumn(JobList.ColumnNameSize)].Value = Utils.FormatSize(this.download.TotalSize);
        }

        public void UpdateStatus()
        {
            this.Cells[this.list.GetColumn(JobList.ColumnNameStatus)].Value = Utils.FormatStatus(this.download.Status);
        }

        public void UpdateProgress()
        {
            int i = this.list.GetColumn(JobList.ColumnNameProgress);
            this.Cells[i].Value = string.Format("{0} %", this.download.Progress);
        }

        public void UpdateTimeLeft()
        {
            this.Cells[this.list.GetColumn(JobList.ColumnNameTimeLeft)].Value = Utils.FormatTime(this.download.TimeLeft);
        }

        public void UpdateTransferRate()
        {
            this.Cells[this.list.GetColumn(JobList.ColumnNameTransferRate)].Value = string.Format("{0:0.00} KB/s", this.download.TransferRate);
        }


    }

}
